﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Atlandiz.Data;

namespace Atlandiz.EnvanterVeZimmetYonetimi
{
    public partial class FormYazilimUretici : DevExpress.XtraEditors.XtraForm
    {
        //MsSqlAccessLayer SQL = new MsSqlAccessLayer(".\\SQLExpress","TeknoEnva",true);

        public int KayID;


        public FormYazilimUretici()
        {
            InitializeComponent();
        }

        public void formuTemizle()
        {
            _txtUnvanString.Text = "";
            _txtAdresString.Text = "";
            _txtTel1String.Text = "";
            _txtTel2String.Text = "";
            _txtFaxString.Text = "";
            _txtEmailString.Text = "";
            _txtUnvanString.Focus();

        }

        private void YazilimUretici_Load(object sender, EventArgs e)
        {
            if (KayID != 0)
            {
                KayitGetir();
            }
            _txtUnvanString.Focus();

        }

        public void KayitGetir()
        {
            //textEdit1.Text = SQL.GetDataCell("Select yuFirmaUnvan from YazilimUretici where yuID=" + KG);
            //textEdit2.Text = SQL.GetDataCell("Select Adres from YazilimUretici where yuID=" + KG);
            //textEdit3.Text = SQL.GetDataCell("Select Tel1 from YazilimUretici where yuID=" + KG);
            //textEdit4.Text = SQL.GetDataCell("Select Tel2 from YazilimUretici where yuID=" + KG);
            //textEdit5.Text = SQL.GetDataCell("Select Fax from YazilimUretici where yuID=" + KG);
            //textEdit6.Text = SQL.GetDataCell("Select Email from YazilimUretici where yuID=" + KG);

            DataTable dt = Army.SQL().GetDataTable("Select yuFirmaUnvan,Adres,Tel1,Tel2,Fax,Email from YazilimUretici where yuID=" + KayID);

            _txtUnvanString.Text = dt.Rows[0][0].ToString();
            _txtAdresString.Text = dt.Rows[0][1].ToString();
            _txtTel1String.Text = dt.Rows[0][2].ToString();
            _txtTel2String.Text = dt.Rows[0][3].ToString();
            _txtFaxString.Text = dt.Rows[0][4].ToString();
            _txtEmailString.Text = dt.Rows[0][5].ToString();




        }


        private void _btnFormuTemizle_Click(object sender, EventArgs e)
        {
            formuTemizle();
        }

        private void _btnKaydet_Click(object sender, EventArgs e)
        {
            if (KayID == 0)
            {
                if (_txtUnvanString.Text.Length > 0)
                {
                    Army.SQL().cmd("Insert YazilimUretici (yuFirmaUnvan,Adres,Tel1,Tel2,Fax,Email) values('" + _txtUnvanString.Text.ToString().Replace("'", "''") + "','" + _txtAdresString.Text.ToString().Replace("'", "''") + "','" + _txtTel1String.Text.ToString().Replace("'", "''") + "','" + _txtTel2String.Text.ToString().Replace("'", "''") + "','" + _txtFaxString.Text.ToString().Replace("'", "''") + "','" + _txtEmailString.Text.ToString().Replace("'", "''") + "')");
                    formuTemizle();
                }

                else
                {
                    MessageBox.Show("Lütfen, Firma Ünvanı alanını doldurunuz.");
                }

            }
            else
            {
                if (_txtUnvanString.Text.Length > 0)
                {
                    Army.SQL().cmd("Update YazilimUretici Set yuFirmaUnvan='" + _txtUnvanString.Text.ToString().Replace("'", "''") + "',  Adres='" + _txtAdresString.Text.ToString().Replace("'", "''") + "', Tel1='" + _txtTel1String.Text.ToString().Replace("'", "''") + "', Tel2='" + _txtTel2String.Text.ToString().Replace("'", "''") + "', Fax='" + _txtFaxString.Text.ToString().Replace("'", "''") + "', Email='" + _txtEmailString.Text.ToString().Replace("'", "''") + "' where yuID=" + KayID);
                    MessageBox.Show("{" + KayID + "} Numaralı Kayıt başarı ile güncellendi.");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Lütfen, Firma Ünvanı alanını doldurunuz.");
                }
            }
        }

        private void _btnKapat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void _btnYazilimUreticiListesi_Click(object sender, EventArgs e)
        {
            ListeYazilimUretici yul = new ListeYazilimUretici();
            yul.ShowDialog();
        }

      
       

    }
}